home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_09 / giglio / testapp.cpp < prev    next >
C/C++ Source or Header  |  1995-07-09  |  3KB  |  97 lines

  1. Listing 5
  2.  
  3. #include <windows.h>
  4. #include "testapp.h"
  5. #include "testenum.h"        // Defines enum
  6.  
  7. // Inline corresponding to first DLL function
  8. inline long MessA(HWND hWnd, int num, LPSTR name)
  9. { return Entry(iFunc_MessA, hWnd, num, name); }
  10.  
  11. // Inline corresponding to second DLL function
  12. inline int MessB(HWND hWnd, LPSTR name, char ch, long blah)
  13. { return Entry(iFunc_MessB, hWnd, name, ch, blah); }
  14.  
  15. // Inline corresponding to third DLL function
  16. inline char MessC(HWND hWnd, char ch)
  17. { return Entry(iFunc_MessC, hWnd, ch); }
  18.  
  19. // Inline corresponding to fourth DLL function
  20. inline LPSTR MessD(HWND hWnd, LPSTR str)
  21. { return (LPSTR)Entry(iFunc_MessD, hWnd, str); }
  22.  
  23. int occurence = 0;
  24. char msg_title[] = "Tester";
  25.  
  26. // Test Dialog Function
  27. BOOL CALLBACK _export MainDlgFunc(HWND hDlg, unsigned msg,
  28.                                   WORD wParam, LONG lParam)
  29. {
  30.   switch(msg) {
  31.   case WM_INITDIALOG:
  32.     break;
  33.   case WM_COMMAND:
  34.     switch(wParam) {
  35.     case UD_TRIGGER1:
  36.       if(MessA(hDlg, ++occurence, "Trigger 1") != 'A')
  37.         MessageBox(hDlg, "DLL func failed", msg_title, IDOK);
  38.       break;
  39.     case UD_TRIGGER2:
  40.       if(MessB(hDlg, "Trigger 2", '~', 0x33009911) != 'B')
  41.         MessageBox(hDlg, "DLL func failed", msg_title, IDOK);
  42.       break;
  43.     case UD_TRIGGER3:
  44.       if(MessC(hDlg, '$') != 'C')
  45.         MessageBox(hDlg, "DLL func failed", msg_title, IDOK);
  46.       break;
  47.     case UD_TRIGGER4:
  48.       if(lstrcmp("BlahBlahBlah", MessD(hDlg, "BlahBlahBlah")))
  49.         MessageBox(hDlg, "DLL func failed", msg_title, IDOK);
  50.       break;
  51.     case IDOK:
  52.     case IDCANCEL:
  53.       PostMessage(hDlg, WM_CLOSE, wParam, 0L);
  54.       return(TRUE);
  55.     default:;
  56.     }
  57.     break;
  58.   case WM_CLOSE:
  59.     PostQuitMessage(0);
  60.     EndDialog(hDlg, wParam);
  61.     return(TRUE);
  62.   default:;
  63.   }
  64.   return(FALSE);
  65. }
  66.  
  67. // WinMain
  68. int FAR PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  69.                        LPSTR lpszCmdLine, int nCmdShow)
  70. {
  71.   if(hPrevInstance)                   // Only allow 1 instance
  72.     return(0);
  73.                                       // Link to the dll
  74.   HANDLE hInstLib = LoadLibrary("testlib.dll");
  75.   if(hInstLib < HINSTANCE_ERROR) {
  76.     MessageBox(NULL, "Fatal: Cannot load library",
  77.                msg_title, MB_OK | MB_ICONEXCLAMATION);
  78.     return(0);
  79.   }
  80.  
  81.   (FARPROC)Entry = GetProcAddress(hInstLib, "Entry");
  82.   if(!Entry) {
  83.     MessageBox(NULL, "Fatal: Cannot get proc address",
  84.                msg_title, MB_OK | MB_ICONEXCLAMATION);
  85.   }
  86.   else {                              // Run the test dialog
  87.     FARPROC lpProc;
  88.  
  89.     lpProc = MakeProcInstance((FARPROC)MainDlgFunc, hInstance);
  90.     DialogBox(hInstance, "MainDlg", NULL, lpProc);
  91.     FreeProcInstance(lpProc);
  92.   }
  93.  
  94.   FreeLibrary(hInstLib);
  95.   return(0);
  96. }
  97.